Skip to content

Fix incompatibility with latest react-query - #10964

Merged
slax57 merged 5 commits into
masterfrom
react-query-bc
Sep 26, 2025
Merged

slax57 merged 5 commits into
masterfrom
react-query-bc

Conversation

@djhi

@djhi djhi commented Sep 25, 2025 •

Copy link
Copy Markdown
Contributor

Problem

Latest react-query (5.89.0) introduced a 4th parameter to all mutation side effect functions (onSucces, onError, onSettled and onMutate) which is a breaking change for us (react-admin won't compile with this version).

Our main issue is that we call those functions ourselves in optimistic and undoable mutation modes.

Solution

Fix it so that it works with whatever version our users are using

How To Test

  • make install build
  • npm create react-admin
  • copy react-admin built packages into the new app node_modules (make sure to delete ./node_modules/react-admin/node_modules which only exists in our monorepo and shouldn't be copied)
  • in the new app, create an edit view and setup the mutationOptions like this:
const PostEdit = () => (
  <Edit mutationOptions={{ onSuccess: () => console.log("Success!") }}>
    <SimpleForm>
      <TextInput source="title" />
    </SimpleForm>
  </Edit>
);
  • hover the onSuccess to see it shows the type for react-query 5.89.0.
  • now install a version of react-query older that 5.89.0 (for instance 5.87.4)
  • npm install @tanstack/react-query@5.87.4
  • You may have to restart your TS server
  • hover the onSuccess again to see it shows the type for react-query 5.87.4.

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature

Also, please make sure to read the contributing guidelines.

@djhi djhi added the RFR Ready For Review label Sep 25, 2025
@fzaninotto
fzaninotto requested a review from Copilot September 25, 2025 10:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Updates react-query dependency to version 5.90.2 to address a breaking change introduced in version 5.89.0. The changes ensure compatibility with both the latest version and older versions of react-query by adapting callback function signatures.

  • Updates react-query dependency across multiple packages from ^5.83.0 to ^5.90.2
  • Modifies callback handlers to use spread operator pattern for version compatibility
  • Updates type definitions for OnSuccess and OnError callbacks to include additional parameters

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/react-admin/package.json Updates react-query dependency version
packages/ra-ui-materialui/package.json Updates react-query dependency version
packages/ra-no-code/package.json Updates react-query dependency version
packages/ra-core/package.json Updates react-query and devtools dependency versions
examples/simple/package.json Updates react-query and devtools dependency versions
packages/ra-core/src/types.ts Adds onMutateResult parameter to OnSuccess and OnError type definitions
packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.tsx Updates callback handlers to use spread operator for compatibility
packages/ra-core/src/dataProvider/*.ts Updates all data provider hooks to use spread operator pattern in callbacks
packages/ra-core/src/controller/*.ts Updates controller hooks to use spread operator pattern in callbacks

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@slax57 slax57 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that everything LGTM. I have not been able to find any signs of a possible regression brought by this PR.

{ snapshot: snapshot.current },
{
client: queryClient,
mutationKey: [resource, 'create', params],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While reviewing I wondered if we shouldn't use callTimeParams here instead, but I realize that we use the same mutationKey while creating the mutation, which may (or may not) be wrong.
In any case, at least it's consistent, so I guess we can ignore this for the context of this PR...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be the same query key as the one passed to useMutation otherwise it will cause issue with offline as you won't be able to target the mutation

{
client: queryClient,
mutationKey: [resource, 'create', params],
meta: mutationOptions.meta,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here however I wonder if you shouldn't use callTimeMeta instead...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that's react-query meta, not react-admin meta

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we actually override them but this is the 4th parameter introduced in latest react-query and I think we should follow the same rule as the query key here

Comment thread packages/ra-core/src/types.ts Resolved
@slax57 slax57 added this to the 5.11.4 milestone Sep 26, 2025
@slax57
slax57 merged commit 827f064 into master Sep 26, 2025
2 checks passed
@slax57
slax57 deleted the react-query-bc branch September 26, 2025 09:24

This branch was successfully deployed

1 active deployment
Preview – react-admin-storybook — 32e4049d Deployed Sep 25, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants